<?php
/**
 * Created by INGEPHP CURD.
 * User: 
 * Date: 2018/10/16
 * Time: 10:16
 */

namespace app\admin\controller;
use app\common\controller\Admin;
use think\facade\Request;
use app\admin\facade\PlatformWechat;

class PlatformWechatController extends Admin
{
    
    /**
     * 列表方法
     * @method get
     * @param int $page 页码
     * @param int $limit 每页数量
     * @param string $keyword 关键词
     * @return json
     */
    public function index()
    {
        $page = Request::param('page','1','intval');
        $limit = Request::param('limit','15','intval');
        $keyword = Request::param('keyword','');
        $res = PlatformWechat::getList($page,$limit,$keyword);
        return $this->results($res);
    }

    /**
     * 表单提交保存操作
     * @method post
     * @param
     * @return json
     */
    public function save()
    {
        $data = Request::param();
        //数据验证
        return $this->results(PlatformWechat::save($data));
    }
    /**
     * 表单提交更新
     * @method post
     * @param int $id 需要更新数据的id
     * @param array  post提交更新的内容
     * @return json
     */
    public function update($id)
    {
        if(!intval($id)){
            $this->results(['code' => 4001, 'msg' => '参数错误', 'data' => '']);
        }
        $data = Request::except('id','post');
        //数据验证
        
        return $this->results(PlatformWechat::update($id,$data));
    }
    /**
     * 表单删除
     * @method get
     * @param int $id 需要删除数据的id
     * @return json
     */
    public function delete($id)
    {
        if(!intval($id)){
            $this->results(['code' => 4001, 'msg' => '参数错误', 'data' => '']);
        }
        return $this->results(PlatformWechat::delete($id));
    }
    /**
     * 根据ID获取单个数据
     * @method get
     * @param int $id 获取的id
     * @return json
     */
    public function read($id)
    {
        return $this->results(PlatformWechat::getById($id));
    }
    /**
     * 根据ID切换status
     * @method get
     * @param int $id 数据id
     * @return json
     */
    public function toggle($id){
        return $this->results(PlatformWechat::toggle($id));
    }
}